package cn.wolfcode.shop.cloud.service.impl;

import cn.wolfcode.shop.cloud.domain.SeckillOrder;
import cn.wolfcode.shop.cloud.mapper.SeckillOrderMapper;
import cn.wolfcode.shop.cloud.service.ISeckillOrderService;
import cn.wolfcode.shop.cloud.service.RedisService;
import cn.wolfcode.shop.cloud.util.SeckillKeyPrefix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SeckillOrderServiceImpl implements ISeckillOrderService {
    @Autowired
    private SeckillOrderMapper seckillOrderMapper;
    @Autowired
    private RedisService redisService;
    @Override
    public SeckillOrder queryBySidAndUid(Long id, Long seckillId) {
        return seckillOrderMapper.queryBySidAndUid(id,seckillId);
    }

    @Override
    public void addSeckillOrder(Long uid, Long seckillId, String orderNo) {
        //把参数封装到对象
        SeckillOrder seckillOrder = new SeckillOrder();
        seckillOrder.setUserId(uid);
        seckillOrder.setOrderNo(orderNo);
        seckillOrder.setSeckillId(seckillId);
       seckillOrderMapper.save(seckillOrder);
        //下单后把数据存到redis里面
        redisService.set(SeckillKeyPrefix.REDIS_SECKILL_ORDER,uid+":"+seckillId,true);



    }
}
